from langchain.schema import BaseOutputParser
from abc import ABC, abstractmethod
from typing import Any, Dict, Generic, List, Optional, TypeVar, Union
T = TypeVar("T")

class DalchemyParser(BaseOutputParser):
    # def parse_result(self, result: List[str]) -> List[]:
    def parse_result(self, result: List[str]) -> List[List[Dict[str,str]]]:  # 批量解析prompts的结果
        """Parse a list of candidate model Generations into a specific format.

        The return value is parsed from only the first Generation in the result, which
            is assumed to be the highest-likelihood Generation.

        Args:
            result: A list of Generations to be parsed. The Generations are assumed
                to be different candidate outputs for a single model input.

        Returns:
            Structured output.
        """
        parsed_results = []
        for res in result:
            parsed_results.append(self.parse(res))
        return parsed_results

    @abstractmethod
    def parse(self, text: str) -> List[Dict[str,str]]: # 单个prompt的输出：解析内容都放入json，即使一个字段；并且用list包裹，即使一条结果。。
        """Parse a single string model output into some structure.

        Args:
            text: String output of a language model.

        Returns:
            Structured output.
        """
